package com.scalosoft.action.token;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.validation.SkipValidation;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
@Namespace(value = "/token")
@InterceptorRefs({
    @InterceptorRef("token"),
    @InterceptorRef("basicStack")
})
@Results({
    @Result(name="init", location="/token/token.jsp"),
    @Result(name="success", location="/token/token-success.jsp"),
    @Result(name="invalid.token", location="/token/token-invalid.jsp")
})
public class TokenAction extends ActionSupport {
	private static final Log log = LogFactory.getLog(TokenAction.class);

	private String nota;
	
	public String getNota() {
		return nota;
	}

	public void setNota(String nota) {
		this.nota = nota;
	}

	@Action(value="token")
	public String execute() {
		log.debug("Token action");
		log.debug("nota :" + nota);
		return SUCCESS;
	}
	
	@Action(value="init")
	public String init() {
		return SUCCESS;
	}
	
	public void validate() {
		if (StringUtils.isEmpty(nota)) {
			addFieldError("nota", "campo richiesto");
		}
	}
}
